var check_pass_word='';var passwords = $('#password').get(0);
$(function(){
    var div = '\
	<div id="key" style="background-color:#A8A8A8;width:99.5%;bottom:0px;">\
		<ul id="keyboard" style="font-size:20px;margin:2px -2px 1px 2px">\
			<li class="symbol"><span class="off">1</span></li>\
			<li class="symbol"><span class="off">2</span></li>\
			<li class="symbol btn_number_"><span class="off">3</span></li>\
			<li class="tab"><span class="off">4</span></li>\
			<li class="symbol"><span class="off">5</span></li>\
			<li class="symbol btn_number_"><span class="off">6</span></li>\
			<li class="tab"><span class="off">7</span></li>\
			<li class="symbol"><span class="off">8</span></li>\
			<li class="symbol btn_number_"><span class="off">9</span></li>\
			<li class="delete lastitem">删除</li>\
			<li class="symbol"><span class="off">0</span></li>\
			<li class="cancle btn_number_">取消</li>\
		</ul>\
	</div>\
	';
    var character,index=0;	$("input.pass").attr("disabled",true);	$("#password").attr("disabled",true);$("#keyboardDIV").html(div);
    $('#keyboard li').click(function(){
        if ($(this).hasClass('delete')) {
        	$(vericodeForm.elements[--index%6]).val('');
        	if($(vericodeForm.elements[0]).val()==''){
        		index = 0;
        	}
            return false;
        }
        if ($(this).hasClass('cancle')) {
            parentDialog.close();
            return false;
        }
        if ($(this).hasClass('symbol') || $(this).hasClass('tab')){
            character = $(this).text();
			$(vericodeForm.elements[index++%4]).val(character);
			if($(vericodeForm.elements[3]).val()!=''){
        		index = 0;
        	}
            if($(vericodeForm.elements[3]).val()!='') {
                var temp_rePass_word = '';
                for (var i = 0; i < vericodeForm.elements.length; i++) {
                    temp_rePass_word += $(vericodeForm.elements[i]).val();
                }
                /** */
                var verifycode =temp_rePass_word;
                if( verifycode == ""){
                    alert("验证码为空");
                    return false;
                }
                if(phone == ""){
                    alert("手机号为空");
                    return false;
                }
                if (verifycode == randomNumber) {
                    console.log(houseId+",openlock");
                    var state=true;
                    var mydata= {
                        "lockState": state,
                        "houseId": houseId
                    }
                    $.ajax({
                        type: 'post',
                        url: 'lock',
                        data:mydata ,
                        beforeSend: function (XMLHttpRequest) {

                        },
                        success: function (data) {
                            alert("验证码正确，即将开锁");
                            $(".close").click();
                        },
                        complete: function (XMLHttpRequest, textStatus) {

                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.log(XMLHttpRequest.status);
                            console.log(XMLHttpRequest.readyState);
                            console.log(textStatus);
                        }
                    });

                    return true;
                } else {
                    alert("验证码错误");
                    return false;
                }
                $("#key").hide();
                var action = 'modify';
			}
        }
        return false;
    });
});
(function () {
    function tabForward(e) {
        e = e || window.event;
        var target = e.target || e.srcElement;
        if (target.value.length === target.maxLength) {
            var form = target.form;
            for (var i = 0, len = form.elements.length-1; i < len; i++) {
                if (form.elements[i] === target) {
                    if (form.elements[i++]) {
                        form.elements[i++].focus();
                    }
                    break;
                }
            }
        }
    }
    var form = document.getElementById("vericodeForm");
    form.addEventListener("keyup", tabForward, false);
})();